package read;

import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;

import java.io.FileWriter;

public class ReadContentByWord {
    public static void main(String[] args) {
        // 创建pdf实例
        PdfDocument doc = new PdfDocument();

        // 加载pdf文件
        doc.loadFromFile("C:/Users/DN/Desktop/简历/张镐麟的简历.pdf");

        // 创建StringBuilder实例
        StringBuilder sb = new StringBuilder();

        // 遍历页面，获取内容添加到StringBuilder
        PdfPageBase page;
        for (int i = 0; i < doc.getPages().getCount(); i++) {
            page = doc.getPages().get(i);
            System.out.println(page.extractText(true));
            sb.append(page.extractText(true));
        }

        FileWriter fileWriter;
        // 将内容写到txt中
        try {
            fileWriter = new FileWriter("res.txt");
            fileWriter.write(sb.toString());
            fileWriter.flush();
        } catch (Exception e) {
            System.out.println("异常：" + e);
        }
        doc.close();

    }
}
